package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.common.exception.CustException;
import com.heima.model.common.constants.wemedia.WmMaterialConstant;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import com.heima.wemedia.service.WmNewsMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
@Api(value = "素材管理controller",tags = "素材管理controller")
public class WmMaterialController {

    @Autowired
    WmMaterialService wmMaterialService;

    @Autowired
    WmNewsMaterialService wmNewsMaterialService;

    /**
     * 上传素材 图片
     * @param multipartFile
     * @return
     */
    @ApiOperation(value = "上传素材")
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(@RequestParam MultipartFile multipartFile){
       return wmMaterialService.uploadPicture(multipartFile);
    }

    @ApiOperation(value = "查询素材")
    @PostMapping("/list")
    public PageResponseResult findList(@RequestBody WmMaterialDTO wmMaterialDTO){
        return wmMaterialService.findlist(wmMaterialDTO);
    }

    @ApiOperation(value = "根据id删除素材")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable("id") Integer id ){
        return wmNewsMaterialService.delPictre(id);
    }

    @ApiOperation(value = "收藏素材")
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id){
        Short collect = WmMaterialConstant.COLLECT;
        return wmMaterialService.updateCollect(id,collect);
    }

    @ApiOperation(value = "取消收藏素材")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id){
        Short collect = WmMaterialConstant.CANCEL_COLLECT;
        return wmMaterialService.updateCollect(id,collect);
    }








}
